import socket
import subprocess
sk=socket.socket()
sk.connect(('127.0.0.1',8080))
while True:
    msg=sk.recv(1024).decode('utf-8')
    if msg=='bye':
        sk.send(b'bye')
        break
    ret=subprocess.Popen(msg,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    #retout=ret.stdout.read()
    #reterr=ret.stderr.read()
    retout=ret.stdout.read()
    reterr=ret.stderr.read()
    sk.send(str(len(retout+reterr)).encode('utf-8'))
    sk.recv(1024)
    sk.send(retout)
    sk.send(reterr)
sk.close()